package com.zrrd.yunchmall;

import com.zrrd.yunchmall.entity.TProduct;
import com.zrrd.yunchmall.repository.TProductRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.IOException;
import java.util.List;

/**
 * @author yekong
 */
@SpringBootTest
@RunWith(SpringRunner.class)
@SuppressWarnings("all")
public class EsTest02 {
    //自动装配一个持久化的实例
    @Autowired
    TProductRepository productRepository;

    //测试自定义的查询方法
    @Test
    public void t8() throws IOException {
        List<TProduct> list = productRepository.findByPname("诺基亚");
        list.forEach(item -> {
            System.out.println(item);
        });
    }

    @Test
    public void t9() throws IOException {
        List<TProduct> list = productRepository.findByPprice(1000);
        list.forEach(item -> {
            System.out.println(item);
        });
    }

    @Test
    public void t10() throws IOException {
        List<TProduct> byPpriceLessThan = productRepository.findByPpriceLessThan(1001);
        byPpriceLessThan.forEach(item -> {
            System.out.println(item);
        });
    }

    @Test
    public void t11() throws IOException {
        List<TProduct> byPpriceLessThan = productRepository.findByPpriceGreaterThan(1001);
        byPpriceLessThan.forEach(item -> {
            System.out.println(item);
        });
    }

    @Test
    public void t12() throws IOException {
        List<TProduct> byPpriceLessThan = productRepository.findByPpriceBetween(1000, 4000); //左闭右闭区间
        byPpriceLessThan.forEach(item -> {
            System.out.println(item);
        });
    }

}
